// @ts-ignore
/* eslint-disable */
import {request} from 'umi';
import {RiskListItem} from './data';
import {TroubleListItem} from "@/pages/Defense/Database/Trouble/data";
import antDesignPro from "@/services/ant-design-pro";

export async function loadRisk(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
}, sorter: any) {
  return request<{
    data: RiskListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/risk/list', {
    method: 'GET',
    params: {
      ...params,
      pageNum: params.current,
      // orderByColumn: "riskSort",
      // isAsc: 'desc',
      orderByColumn: Object.keys(sorter)[0],
      isAsc: Object.values(sorter)[0],
      type: 0,
    },
  });
}

export async function loadCheckRisk(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
}, sorter: any) {
  return request<{
    data: RiskListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/risk/list', {
    method: 'GET',
    params: {
      ...params,
      pageNum: params.current,
      // orderByColumn: "riskSort",
      // isAsc: 'desc',
      orderByColumn: Object.keys(sorter)[0],
      isAsc: Object.values(sorter)[0],
      type: 1,
    },
  });
}


export async function download() {
  request(`/v2/enterprise/risk/template`, {
    method: 'POST',
    // 必须加responseType: 'blob',
    responseType: 'blob',
  }).then((res) => {
    const objectURL = URL.createObjectURL(res);
    let btn = document.createElement('a');
    btn.download = '风险导入模板.xlsx'; //文件类型
    btn.href = objectURL;
    btn.click();
    URL.revokeObjectURL(objectURL);
    // @ts-ignore
    btn = null;
  });
}

export async function checkFirst(param: TroubleListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/first', {method: 'GET',});
}
export async function doFirst(param: TroubleListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/first', {method: 'POST',});
}

export async function distribute(param: TroubleListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/distribute', {method: 'POST',});
}

export async function initRisk(param: TroubleListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/init', {method: 'POST',});
}

export async function getRisk(param: { riskId?: number }): Promise<{ data: RiskListItem }> {
  console.log(param);
  return request(`/v2/enterprise/risk/${param.riskId}`, {method: 'GET'});
}

export async function addRisk(param: RiskListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk', {method: 'POST', data: param});
}

export async function updateRisk(param: RiskListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk', {method: 'PUT', data: param});
}

export async function checkRisk(param: RiskListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/check', {method: 'PUT', data: param});
}

export async function rejectRisk(param: RiskListItem): Promise<{ data: number }> {
  return request('/v2/enterprise/risk/reject', {method: 'PUT', data: param});
}

export async function removeRisk(data: number[]) {
  return request<Record<string, any>>(`/v2/enterprise/risk/` + data.join(), {method: 'DELETE'});
}
